#include "service/include/swei_cache.h"
#include "service/include/swei_uplink.h"
#include "service/include/swei_blinddata.h"
#include "lettershell/shell.h"
#include "global.h"
#include "comm/co_heartbeat.h"
#include "task/gsensor/gsensor.h"
#include "drivers/sensor/sensor_support.h"
#include <stdio.h>
#include <sensor/icm42670/sensor_icm42670.h>


int32_t shell_snsr_print(int32_t argc, char *argv[])
{
    uint32_t alarm_state = gsensor_alarm_state_get();
    printf("***********************************************************\r\n");
    printf("CoMCU Power Status      :%s\r\n", is_ebike_mcu_off() ? "OFF" : "ON");
    printf("CoMCU Auth  Status      :%s\r\n", get_auth_status() ? "DOING" : "READY");
    printf("Move Alarm Status       :%s\r\n", (alarm_state & ALARM_MOVE_MASK) ? "ENABLE": "DISABLE");
    printf("Unusal Move Alarm Status:%s\r\n", (alarm_state & ALARM_UNUSUAL_MOVE_MASK) ? "ENABLE": "DISABLE");
    printf("TILT Alarm Status       :%s\r\n", (alarm_state & ALARM_TILT_MASK) ? "ENABLE": "DISABLE");
    printf("ROLL Alarm Status       :%s\r\n", (alarm_state & ALARM_ROLL_MASK) ? "ENABLE": "DISABLE");
    printf("***********************************************************\r\n");
    printf("ACC Value               :\r\n") ;
    printf("***********************************************************\r\n");

    return 0;
}
 
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_DISABLE_RETURN,
                 snsr, 
                 shell_snsr_print, 
                 show the snsr status);


/**
 * @brief 使能低功耗和中断
 */
void shell_snsr_clr(void)
{
    sensor_lowpower_initialize();
    clear_wom_int_flags();
}
 
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_DISABLE_RETURN,
                 snsr_clr, 
                 shell_snsr_clr, 
                 clear the snsr status);

/**
 * @brief 测试接口，清除中断标志
 */
void shell_snsr_int_clr(void)
{
    clear_wom_int_flags();
}
 
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_DISABLE_RETURN,
                 snsr_int_clr, 
                 shell_snsr_int_clr, 
                 clear the snsr status);

/**
 * @brief 测试接口，清除中断标志
 */
void shell_snsr_lowpower(void)
{
    sensor_lowpower_initialize();
}
 
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_DISABLE_RETURN,
                 snsr_lowpower, 
                 shell_snsr_lowpower, 
                 clear the snsr status);

/**
 * @brief 测试接口，清除中断标志
 */
void shell_snsr_alarm_report(void)
{
    swei_alarm_setup(ALARM_SHAKE);
    swei_alarm_setup(ALARM_TILT);
    swei_alarm_setup(ALARM_TUMBLING);
    swei_alarm_setup(ALARM_ABNORMAL_MOVE);
}
 
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_DISABLE_RETURN,
                 snsr_alarm_report, 
                 shell_snsr_alarm_report, 
                 report the snsr alarm);